import "package:ct_pa_majordomo/utils/request.dart";
import "package:dio/dio.dart";

class ApartmentApi {


  Future<Map> createApartment(data) async {
  Response response = await request.post(
  "apartment/apartment",
    data: data,
  );
  return response.data ?? {};
  }

  // 获取公寓信息
  Future<Map> getApartmentInfo() async {
    Response response = await request.get(
      "apartment/apartment",
    );
    return response.data ?? {};
  }

  // 修改公寓信息
  Future<Map> updateApartmentInfo(data) async {
    Response response = await request.put(
      "apartment/apartment",
      data: data,
    );
    return response.data ?? {};
  }

  // 设置未开门提醒时间
  Future<Map> doorUnlockedReminder(days) async {
    Response response = await request.put(
      "apartment/apartment/door-unlocked-reminder",
      queryParameters: { "days": days },
    );
    return response.data ?? {};
  }

  Future<List> getGroups() async {
    Response response = await request.get("apartment/group/list");
    return response.data["rows"] ?? [];
  }

  Future<List> getStatus() async {
    Response response =
        await request.get("system/dict/data/type/sys_room_status");
    return response.data["data"] ?? [];
  }

  Future<List> getApartments() async {
    Response response = await request.get("apartment/building/list");
    return response.data ?? [];
  }

  Future<Map> getApartmentRooms(queryParameters) async {
    Response response = await request.get(
      "apartment/room/list",
      queryParameters: queryParameters,
    );
    return response.data ?? {};
  }

  // 新建整栋
  Future<Map> createBuilding(queryParameters) async {
    Response response = await request.post(
      "apartment/building/create",
      data: queryParameters,
    );
    return response.data ?? {};
  }


  // 获取整栋公寓列表
  Future<List> getBuildingList({dynamic? queryParameters}) async {
    Response response = await request.get(
      "apartment/building/list",
      queryParameters: queryParameters,
    );
    return response.data ?? [];
  }

  // 删除整层
  Future<Map> removeFloor(queryParameters) async {
    Response response = await request.delete(
      "apartment/floor/${queryParameters['floorIds']}",
        queryParameters: { "buildingId": queryParameters["buildingId"], "apartmentId": queryParameters["apartmentId"] }
    );
    return response.data ?? {};
  }

  Future<Map> getRoomList(queryParameters) async {
    Response response = await request.get(
        "apartment/room/select",
        queryParameters: queryParameters
    );
    return response.data ?? {};
  }

  /// 获取空房间列表
  Future<Map> getEmptyRoomList(queryParameters) async {
    Response response = await request.get(
        "apartment/room/empty-list",
        queryParameters: queryParameters
    );
    return response.data ?? {};
  }

  Future<Map> getRoomInfo(int roomId) async {
    Response response = await request.get(
        "apartment/room/$roomId"
    );
    return response.data ?? {};
  }

  // 办理入住
  Future<Map> checkIn(queryParameters) async {
    Response response = await request.post(
        "apartment/check-in",
      data: queryParameters,
    );
    return response.data ?? {};
  }

  // 修改入住信息
  Future<Map> updateCheckIn(queryParameters) async {
    Response response = await request.put(
      "apartment/check-in",
      data: queryParameters,
    );
    return response.data ?? {};
  }

  // 办理退房
  Future<Map> checkOut(int checkId) async {
    Response response = await request.put(
      "apartment/check-in/out/$checkId",
    );
    return response.data ?? {};
  }

  // 修改房间信息
  Future<Map> updateRoomInfo(queryParameters) async {
    Response response = await request.put(
      "apartment/room",
      data: queryParameters,
    );
    return response.data ?? {};
  }

  // 删除房间
  Future<Map> removeRoom({required String roomIds}) async {
    Response response = await request.delete(
      "apartment/room/$roomIds",
    );
    return response.data ?? {};
  }

  // 房间关联设备列表
  Future<Map> deviceList(int roomId) async {
    Response response = await request.get(
      "apartment/room/device-list/$roomId",
    );
    return response.data ?? {};
  }

  // 无关联设备的房间列表
  // type 1：门锁 2：电表
  Future<Map> unboundDeviceRooms(String type, queryParameters) async {
    Response response = await request.get(
      "apartment/room/not-bind-list/$type",
      queryParameters: queryParameters,
    );
    return response.data ?? {};
  }

  // 清理房间
  Future<Map> cleanRoom(int roomId) async {
    Response response = await request.put(
      "apartment/room/clean/$roomId"
    );
    return response.data ?? {};
  }

  // 标记房间为脏
  Future<Map> dirtyRoom(int roomId) async {
    Response response = await request.put(
      "apartment/room/dirty/$roomId"
    );
    return response.data ?? {};
  }


}

ApartmentApi apartmentApi = ApartmentApi();
